
function loaddata(){
	var allFlag = $("#allFlag").val();
	var pno = $("#pagenum").val();
	var emp_id = $("#emp_id").val();
	var ope_id=$("#ope_id_Ary").val();
	var month= $("#month").val();
	var classtype= $("#classtype").val();

	var url = pms_url + "ary/performance/getListWorkAbility";
	var params = {
			emp_id:emp_id,
			ope_id:ope_id,
			month:month,
			pno:pno,
			classtype:classtype,
			allFlag:allFlag
			};
	var obj = load(url,params);
	var workabilityArray = obj.workability;
	$("#performanceMaintainMonlist").find("tbody").html("");
	$.each(workabilityArray, function(index, p) {
	var tr ="<tr role='row'>"+
	"<td align='center'>"+(index+1)+"</td>"+
	"<td align='center'>"+p.label+"</td>"+
	"<td align='center'>"+p.emp_id+"</td>"+
	"<td align='center'>"+p.emp_name+"</td>"+
	"<td align='center'>"+p.gender+"</td>"+
	"<td align='center'>"+((p.classtype==null)?"":p.classtype)+"</td>"+
	"<td align='center'>"+p.workAbility+"</td>"+
	"<td align='center'><button type='button' class='btn btn-xs blue btn-outline'>编辑</button></td>"+
	"</tr>";
	//alert(tr);
	$("#performanceMaintainMonlist").find("tbody").append(tr);
 });
}




$(function () { 
	
	loaddata();
	$("#btnSearch").click(function(){
		loaddata();
	});
	$("#btnReset").on('click', function () {
		$("#searchform input").val("");
		$("#ope_id").val("");
	});	
	
	
	
	$("#btnExport").on('click', function () {
		$("#performanceMaintainMonlist").tableExport({
		    headings: true, 
		    footers: true, 
		    formats: ["xls"],
		    fileName: "data",
		    bootstrap: true,
		    position: "bottom",
		    ignoreRows: null,
		    ignoreCols: null
		});   

	});	
	
	
	$(document).on('click', "td>button",function () {	
    	var workability="";
    	var emp_id= $(this).parent().parent().children("td:eq(3)").html();
    	var month = $("#month").val();
        $(this).parent().parent().children("td:eq(6)").each(function() {
        	var tdObj = $(this); 
            obj_text = $(this).find("input:text");
            if(!obj_text.length)  
            	{
            		var inputObj = $("<input type='text' value='" + $(this).text() + "'/>"); 
            		inputObj.click(function () {  
            		            return false;  
            		}); 
                    inputObj.width(tdObj.width()-100);  
                    inputObj.css("margin", 0);  
                    inputObj.css("padding", 0);  
                    inputObj.css("text-align", "center");  
                    inputObj.css("background-color", tdObj.css("background-color"));  
                    tdObj.html(inputObj);
            	}
            else  {
            	$(this).html(obj_text.val());
            	var num = $(this).parents("tr").find("td").index($(this));
            	if(num==6) workability=obj_text.val();
            }
            
            
        });

     if($(this).html()=="确定"){
            if (isNaN(workability)){
	              alert("必须输入数字！"); 
	              return;
             }
            	
			if(parseInt(workability)>30) {
				alert("工作能力最高分是30,请确认！");
				loaddata();
				return;
			}
            	
			var param={month:month,emp_id:emp_id,workability:workability};
			var url=pms_url+"ary/performance/updateWorkability";
			$.post(url, param, function(data) {},"json");
        }
        var str = $(this).html()=="编辑"?"确定":"编辑";  
        $(this).html(str); 
        
});
	
	
  });